package com.cloud.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.api.domain.sys.GlobalDataPermit;
import com.cloud.base.mapper.GlobalDataPermitMapper;
import com.cloud.base.service.IGlobalDataPermitService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author haohaibo
 * @since 2024-10-14
 */
@Service("globalDataPermitService")
public class GlobalDataPermitServiceImpl extends ServiceImpl<GlobalDataPermitMapper, GlobalDataPermit> implements IGlobalDataPermitService {

    @Resource(name = "myRedis")
    private RedisTemplate<String,Object> redisTemplate;
@Resource
private GlobalDataPermitMapper globalDataPermitMapper;
    @Override
    public List<String> selectDataPermitList() {
      /*  Set<Object> funIds = redisTemplate.opsForSet().members("spring_cache_funIds");
        if (funIds == null || funIds.isEmpty()){
            List<GlobalDataPermit> list = list();
            return list.stream().map(GlobalDataPermit::getFunId).collect(Collectors.toSet());
        }else {
            return funIds;
        }*/
      return   globalDataPermitMapper.selectAll();
    }

    @Override
    public void InsertOrUpdateDataPermit(GlobalDataPermit para) {
        redisTemplate.opsForSet().add("spring_cache_funIds",para.getFunId());
        saveOrUpdate(para);
    }
}